<include file="Public/head" />
<style type="text/css">
    .tanShang .daiJingW{padding: 20px 0 0 10px;}
    .tanShang6 .cardealer-zhanghao{width:560px;}
    .tanShang6{height:280px;}
    .tanShang6 .cardealer-zhanghao{height:30px; line-height:30px;margin:0; text-align:left; overflow:hidden;}
    .tanShang6 .cardealer-zhanghao span{width:150px; text-align:right;float:left; display:block;}
    .tanShang6 .cardealer-zhanghao em{color:#20ab4f;padding:0;font-size:14px;}
</style>
</head>
<include file="Public/common_header" />


    <div class="mian">
        <include file="Public/sidebar" menu='cwgl.bzjgl' />
        <div class="mianR">
            <h3 class="yonghu">保证金管理</h3>

            <div class="listBox">
                <div class="yuList">
                  <form action="/Bail/index" method="get">
                    <div class="yuSuo clearfix" style="float:left;">
                        <input name="dealer_id" type="text" value="{$params.dealer_id}" placeholder="车商ID" class="suoDian suoDian1" />
                        <input name="contact_person" type="text" value="{$params.contact_person}" placeholder="公司联系人" class="suoDian suoDian1" />
                        <input name="contact_mobile" type="text" value="{$params.contact_mobile}" placeholder="联系人电话" class="suoDian suoDian1" />
                        <input type="submit" value="搜索" class="suoSou" style="width:80px;" />
                        <input type="button" onclick="window.location.href='/Bail/index'" value="重置" class="suoSou" style="width:80px;" />
                    </div>
                  </form>
                    <div class="clear"></div>
                    <table class="table" style="margin-top: 0px;">
                        <thead>
                            <tr>
                                <td width="10%">车商ID</td>
                                <!--<td width="10%">车商帐号</td>-->
                                <td width="10%">公司联系人</td>
                                <td width="15%">联系人电话</td>
                                <td width="10%">保证金总额</td>
                                <td width="10%">可用金额</td>
                                <td width="10%">冻结金额</td>
                                <td width="10%">累计赔付</td>
                                <td width="10%">维保透支金额</td>
                                <td width="13%">操作</td>
                            </tr>
                        </thead>
                        <tbody>
                        <foreach name="list" item="row" >
                            <tr>
                                <td>{$row.dealer_id}</td>
                                <!--<td>{$row.user_name}</td>-->
                                <td>{$row.contact_person}</td>
                                <td>{$row.contact_mobile}</td>
                                <td>{$row['bail_amount'] + $row['freeze_amount']}</td>
                                <td>{$row.bail_amount}</td>
                                <td>{$row.freeze_amount}</td>
                                <td>{$row.indemnity_amount}</td>
                                <td>{$row.minus_amount}</td>
                                <td>
                                    <?php if($chakan_auth===true):?>
                                    <a href="/Bail/detail/dealer_id/{$row.dealer_id}" target="_blank">查看</a>
                                    <?php endif;?>
                                    <?php if($recharge_auth===true):?>
                                    <a href="javascript:add_price({$row.dealer_id})">充值</a>
                                    <?php endif;?>
                                    <?php if($extarct_auth===true):?>
                                    <a href="javascript:get_price({$row.dealer_id})">提取</a>
                                    <?php endif;?>
                                </td>
                            </tr>
                        </foreach>
                        </tbody>
                    </table>
                </div>
            </div>


            <div class="pageFaye">
                <div class="pager">
                    <span name="first" class="disabled" style="cursor: default;"><a num="{$page_data.first.num}" href="{$page_data.first.url}">首页</a></span>
                    <span name="prev" class="disabled" style="cursor: default;"><a num="{$page_data.prev.num}" href="{$page_data.prev.url}">上一页</a></span>
                    <span name="nav_fix" style="cursor: pointer;">
                        <?php foreach ($page_data['link_page'] as $page => $link): ?>
                        <?php if($page == $p){ ?>
                        <a class="navi"  num="<?php echo $page;?>" href="<?php echo $link;?>">
                            <font style="color:#fff"><?php echo $page;?></font>
                        </a>	
                        <?php }else{?>
                        <a class="navi"  num="<?php echo $page;?>" href="<?php echo $link;?>">
                            <?php echo $page;?>
                        </a>
                        <?php }?>
                        <?php endforeach ?>								
                    </span>
                    <span name="next" class="pageNext" style="cursor: pointer;"><a num="{$page_data.next.num}"  href="{$page_data.next.url}">下一页</a></span>
                    <span name="last" class="pageLast" style="cursor: pointer;"><a num="{$page_data.end.num}"  href="{$page_data.end.url}">末页</a></span>
                </div>
                <div class="clear"></div>
            </div>

            <!--充值弹出窗口-->
            <div class="yunBei price_01" style="display:none"></div>
                <form id="add_fm">
                    <div class="tanShang tanShang6 add_tanShang" style="display:none">
                        <h3>保证金充值</h3>
                        <ul class="daiJingW">
                            <li class="cardealer-zhanghao">
                                <span>
                                    车商账号：
                                </span>
                                <em id="dealer_user_name_01"></em>
                            </li>
                            <li class="cardealer-zhanghao">
                                <span>
                                    车商联系人：
                                </span>
                                <em id="dealer_contact_person_01"></em>
                            </li>
                            <li class="cardealer-zhanghao">
                                <span>
                                    保证金余额：
                                </span>
                                <em id="bail_amount_01"></em> <em>元</em>

                            </li>
                            <li class="clearfix">
                                <span style="width:90px; text-align:right;float:left;margin-left:20px;">充值金额：</span>
                                <input type="text" name="add_price" onclick="if (this.value == '请输入金额')
                                            this.value = '';" value="请输入金额" />
                                <em>元</em>
                            </li>
                            <li class="clearfix">
                                <input type="hidden" name="dealer_id_01">
                                <input type="button" value="确定" class="queding" id="qd_add_price"/>
                                <input type="button" value="取消" class="quxiao" />
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
        <!--您已充值成功-->
        <!--提取弹出窗口-->
        <div class="yunBei price_02" style="display:none"></div>
        <form id="get_fm">
            <div class="tanShang tanShang6 get_tanShang" style="display:none">
                <h3>保证金提取</h3>
                <ul class="daiJingW">
                    <li class="cardealer-zhanghao">
                        <span>
                            车商账号： 
                        </span>
                        <em id="dealer_user_name_02"></em>
                    </li>
                    <li class="cardealer-zhanghao">
                        <span>
                            车商联系人： 
                        </span>
                        <em id="dealer_contact_person_02"></em>
                    </li>
                    <li class="cardealer-zhanghao">
                        <span>
                            维保查询透支金额：
                        </span>
                        <em id="minus_amount"></em> <em>元</em>
                    </li>
                    <li class="cardealer-zhanghao">
                        <span>
                            保证金余额： 
                        </span>
                        <em id="bail_amount_02"></em> <em>元</em>
                    </li>
                    <li class="cardealer-zhanghao">
                        <span>提取金额：</span>
                        <input type="text" name="get_price" onclick="if (this.value == '请输入金额')
                                    this.value = '';" value="请输入金额" style="width: 150px;" />
                        <em> 元</em>
                    </li>
                    <li class="clearfix" style="margin-top: 10px;">
                        <input type="hidden" name="dealer_id_02">
                        <input type="button" value="确定" class="queding" id="qd_get_price"/>          
                        <input type="button" value="取消" class="quxiao" />          
                    </li>
                </ul>
            </div>

    </div>
    <!--提取保证金成功-->
    <script type="text/javascript">
        $('#fm .pageFaye a').click(function () {
            $('#p').val($(this).attr('num'));
            $('#fm').submit();
            return false;
        });
    </script>
</div>
</form>
<div class="clear"></div>
</div>
<script type="text/javascript">
    /**
     * 充值保证金
     * @param {type} dealer_id
     * @returns {undefined}
     */
    function add_price(dealer_id) {
        $.post('/Bail/get_dealer_info', {'dealer_id': dealer_id}, function (data) {
            $("#dealer_user_name_01").html(data.user_name);
            $("#dealer_contact_person_01").html(data.contact_person);
            $("#bail_amount_01").html(data.bail_amount);
            $("input[name='dealer_id_01']").val(dealer_id);
            $('.price_01,.add_tanShang').show();
        }, 'json');
    }
    /**
     * 确定充值保证金
     */
    $("#qd_add_price").on("click", function () {
        dealer_id = $("input[name='dealer_id_01']").val();
        add_price_val = $("input[name='add_price']").val();
        post_data = {
            'dealer_id': dealer_id,
            'price': add_price_val
        }
        var btn_obj = $(this);
        btn_obj.val("提交中...").attr("disabled", 'disabled');
        $.post("/Bail/add_price/", post_data, function (data) {
            try {
                if (data.code == 200) {
                    delay_alert('充值成功!', 300);
                    setTimeout(function () {
                        btn_obj.val("确定").removeAttr("disabled style");
                        window.location.reload();
                    }, 400);
                } else {
                    btn_obj.val("确定").removeAttr("disabled style");
                    delay_alert(data.msg, 300);
                }
            } catch (e) {
                btn_obj.val("确定").removeAttr("disabled style");
                delay_alert('充值失败!', 300);
            }
        }, 'json');
    });
    /**
     * 提取保证金
     */
    function get_price(dealer_id) {
        $.post('/Bail/get_dealer_info', {'dealer_id': dealer_id}, function (data) {
            $("#dealer_user_name_02").html(data.user_name);
            $("#dealer_contact_person_02").html(data.contact_person);
            $("#minus_amount").html(data.minus_amount);
            $("#bail_amount_02").html(data.bail_amount);
            $("input[name='dealer_id_02']").val(dealer_id);
            $('.price_02,.get_tanShang').show();
        }, 'json');
    }
    /**
     * 确定提取保证金
     */
    $("#qd_get_price").on("click", function () {
        get_price_val = $("input[name='get_price']").val();
        dealer_id = $("input[name='dealer_id_02']").val();
        post_data = {
            'dealer_id': dealer_id,
            'price': get_price_val
        }
        var btn_obj = $(this);
        btn_obj.val("提交中...").attr("disabled", 'disabled');
        $.post("/Bail/get_price", post_data, function (data) {
            try {
                if (data.code == 200) {
                    delay_alert('提取成功!', 300);
                    setTimeout(function () {
                        btn_obj.val("确定").removeAttr("disabled style");
                        window.location.reload();
                    }, 400);
                } else {
                    btn_obj.val("确定").removeAttr("disabled style");
                    delay_alert(data.msg, 300);
                }
            } catch (e) {
                btn_obj.val("确定").removeAttr("disabled style");
                delay_alert('提取失败!', 300);
            }
        }, 'json');
    });
</script>
<include file="Public/foot" />